﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AmuTools;
using app.Api;

namespace app.Models
{
    [Model(TableName = "t_service_item", PrimaryKey = "id", IdentityInsert = false, BaseID = "1000000000")]
    public class ServiceItem
    {
        [Field(Description = "唯一标识符")]
        public int id { get; set; }


        [Field(DataType = "nvarchar(MAX)", Description = "编号 = sv + 时间戳 + 服务机构id")]
        public string number { get; set; }


        [Field(Description = "标题")]
        public string title { get; set; }


        [Field(Webable = false, Description = "发布服务者的ID")]
        public string member_id { get; set; }


        private Member _member = null;
        [Field(Storageable = false, Description = "发布服务者")]
        public Member member
        {
            get
            {
                if (_member == null)
                {
                    _member = G.DB.GetById<Member>(this.member_id);
                }
                return _member;
            }
            set
            {
                _member = value;
                member_id = _member.id.ToString();
            }
        }


        [Field(Description = "需求平台模块类别")]
        public string m_type { get; set; }


        [Field(Description = "服务类别，便于后期搜索分类")]
        public string service_type { get; set; }

        
        [Field(DataType = "nvarchar(MAX)", Description = "主要内容概要，如主要用途等")]
        public string service_content { get; set; }


        [Field(DataType = "nvarchar(100)", Description = "服务对象")]
        public string service_people { get; set; }


        [Field(DataType = "nvarchar(MAX)", Description = "申报条件，即企业想要申请该服务需要满足的条件")]
        public string requirement { get; set; }


        [Field(DataType = "nvarchar(MAX)", Description = "服务特色")]
        public string service_feature { get; set; }


        [Field(Storageable = false, IsPrivate = true, Description = "服务步骤")]
        public List<Step> steps
        {
            get
            {
                return Step.GetSteps(id);
            }
        }


        [Field(Description = "服务部门")]
        public string service_department { get; set; }


        [Field(Description = "联系人")]
        public string service_master { get; set; }


        [Field(DataType = "nvarchar(11)", Description = "联系人电话")]
        public string service_tele { get; set; }


        [Field(Description = "联系人地址")]
        public string service_address { get; set; }


        [Field(Description = "需要提交的资料，即企业想要申请该服务需要提交的资料")]
        public string needFileds { get; set; }

        //该字段暂时没用
        [Field(Description = "审批时间，希望管理员在多长时间内审核完毕")]
        public string approve_time { get; set; }


        [Field(DataType = "nvarchar(MAX)", Description = "备注")]
        public string Remark { get; set; }


        [Field(DataType = "char(13)", Description = "创建时间")]
        public string create_time { get; set; }


        [Field(DataType = "char(13)", Description = "结束时间")]
        public string finish_time { get; set; }


        private string _appendix_ids = "";
        [Field(Description = "附件ID数组")]
        public string appendix_ids {
            get { return _appendix_ids; }
            set
            {
                _appendix_ids = value;
                _appendix = null;
            }
        }
      

        private List<UploadedFile> _appendix = null;
        [Field(Storageable = false, Description = "附件数组")]
        public List<UploadedFile> appendix {
            get
            {
                if(_appendix == null)
                {
                    if (appendix_ids == "") _appendix = new List<UploadedFile>();
                    else _appendix = G.DB.Get<UploadedFile>(string.Format("{0} in ({1})", G.DB.GetPrimaryKey<UploadedFile>(), appendix_ids)).GetFirstTableList<UploadedFile>();
                }
                return _appendix;
            }
        }


        [Field(Description = "该条服务的状态")]
        public int status { get; set; }


        [Field(Description = "被浏览次数")]
        public int view_times { get; set; }


        [Field(Description = "服务次数")]
        public int trade_times { get; set; }


        [Field(Webable = false, Description = "是否已被删除")]
        public int is_delete { get; set; }


        [Field(Description = "允许excel显示的字段")]
        static public Dictionary<string, string> ExcelColumns
        {
            get
            {
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add("number", "编号");
                dic.Add("title", "服务名称");
                dic.Add("create_time", "添加时间");
                dic.Add("status", "状态");
                return dic;
            }
        }


        //public static ServiceItem[] GetInitData() {
        //    return new ServiceItem[] {
        //           new ServiceItem{ id=1,title="五个亿，干大事儿" }
        //    };
        //}
    }
    
}